package org.luxor.commons.selenium.listener;

import org.luxor.commons.core.utils.UuidUtils;
import org.luxor.commons.selenium.component.Context;
import org.luxor.commons.selenium.component.SeleniumDriver;
import org.luxor.commons.selenium.component.command.SeleniumCommand;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Selenium 事件监听器抽象类
 *
 * @author Mr.yan  @date 2022/4/10
 */
public class AbstractSeleniumEventListener implements SeleniumEventListener {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    public AbstractSeleniumEventListener() {
    }

    @Override
    public void init(SeleniumCommand command, Context context) {
        context.setTrackId(UuidUtils.uuid32());
    }

    @Override
    public void beforeExecute(SeleniumDriver webDriver, SeleniumCommand command, Context context) {
    }

    @Override
    public void afterExecute(SeleniumDriver webDriver, SeleniumCommand command, Context context) {
    }

    @Override
    public void onException(Throwable throwable, WebDriver driver) {
    }

    @Override
    public void beforeAlertAccept(WebDriver driver) {
        log.trace("Enter beforeAlertAccept Event.");
    }

    @Override
    public void afterAlertAccept(WebDriver driver) {
        log.trace("Enter afterAlertAccept Event.");
    }

    @Override
    public void afterAlertDismiss(WebDriver driver) {
        log.trace("Enter afterAlertDismiss Event.");
    }

    @Override
    public void beforeAlertDismiss(WebDriver driver) {
        log.trace("Enter beforeAlertDismiss Event.");
    }

    @Override
    public void beforeNavigateTo(String url, WebDriver driver) {
        log.trace("Enter beforeNavigateTo Event. url:{}", url);
    }

    @Override
    public void afterNavigateTo(String url, WebDriver driver) {
        log.trace("Enter afterNavigateTo Event. url:{}", url);
    }

    @Override
    public void beforeNavigateBack(WebDriver driver) {
        log.trace("Enter beforeNavigateBack Event.");
    }

    @Override
    public void afterNavigateBack(WebDriver driver) {
        log.trace("Enter afterNavigateBack Event.");
    }

    @Override
    public void beforeNavigateForward(WebDriver driver) {
        log.trace("Enter beforeNavigateForward Event.");
    }

    @Override
    public void afterNavigateForward(WebDriver driver) {
        log.trace("Enter afterNavigateForward Event.");
    }

    @Override
    public void beforeNavigateRefresh(WebDriver driver) {
        log.trace("Enter beforeNavigateRefresh Event.");
    }

    @Override
    public void afterNavigateRefresh(WebDriver driver) {
        log.trace("Enter afterNavigateRefresh Event.");
    }

    @Override
    public void beforeFindBy(By by, WebElement element, WebDriver driver) {
        log.trace("Enter beforeFindBy Event. by:{}", by);
    }

    @Override
    public void afterFindBy(By by, WebElement element, WebDriver driver) {
        log.trace("Enter afterFindBy Event. by:{}", by);
    }

    @Override
    public void beforeClickOn(WebElement element, WebDriver driver) {
        log.trace("Enter beforeClickOn Event. element:{}", element);
    }

    @Override
    public void afterClickOn(WebElement element, WebDriver driver) {
        log.trace("Enter afterClickOn Event. element:{}", element);
    }

    @Override
    public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
        log.trace("Enter beforeChangeValueOf Event. element:{} / keysToSend:{}", element, keysToSend);
    }

    @Override
    public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {
        log.trace("Enter afterChangeValueOf Event./ keysToSend:{}", element, keysToSend);
    }

    @Override
    public void beforeScript(String script, WebDriver driver) {
        log.trace("Enter beforeScript Event. script:{}", script);
    }

    @Override
    public void afterScript(String script, WebDriver driver) {
        log.trace("Enter afterScript Event. script:{}", script);
    }

    @Override
    public void beforeSwitchToWindow(String windowName, WebDriver driver) {
        log.trace("Enter beforeSwitchToWindow Event. windowName:{}", windowName);
    }

    @Override
    public void afterSwitchToWindow(String windowName, WebDriver driver) {
        log.trace("Enter afterSwitchToWindow Event. windowName:{}", windowName);
    }

    @Override
    public <X> void beforeGetScreenshotAs(OutputType<X> target) {
        log.trace("Enter beforeGetScreenshotAs Event.");
    }

    @Override
    public <X> void afterGetScreenshotAs(OutputType<X> target, X screenshot) {
        log.trace("Enter afterGetScreenshotAs Event.");
    }

    @Override
    public void beforeGetText(WebElement element, WebDriver driver) {
        log.trace("Enter beforeGetText Event. element:{}", element);
    }

    @Override
    public void afterGetText(WebElement element, WebDriver driver, String text) {
        log.trace("Enter afterGetText Event. element:{} text:{}", element, text);
    }

}
